﻿/**
 * @author sminutoli
 */

import com.dinmax.flash.sof.*;
import com.dinmax.requirement.user.*;

class UserFactory implements SOFService {
	
	private var service:String;	 
	private var user:User;
	private var NEW_USER:String="AddUser";
	private var UPDATE_USER:String="ModifyUser";
	
	public static function newInstance():UserFactory {
		return new UserFactory();
	}
	
	public function save(user:User) {
		this.user=user;
		service=UPDATE_USER;
		//Si el ID es indefinido es un alta
		if (user.getId()==undefined) {
			service=NEW_USER;
		}
		var manager:SOFManager=SOFManager.newInstance();
		manager.execute(this);					
	}
	
	function error(error:SOFServiceError) {
		trace("RequirementFactory.as | error()");
	}
	
	function getName():String {
		return this.service;
	}
	
	function getParameters():SOFServiceData {
		var parameters=new SOFServiceData();
		parameters.addClass("User", user);
		return parameters;
	}
	
	function result(data:SOFServiceData):Void {
		trace("RequirementFactory.as | result()");
	}
	
}